<template>
	<gracePage headerBG="#FFFFFF" class="indexPage" :customHeader="false">
		<!-- <view slot="gHeader" style="padding:0 25rpx;">
			
		</view> -->
		<view slot="gBody" class="grace-flex-v1" id="gBody">
			<graceNavBar :items="params.navListItem" :currentIndex="params.currentIndex" textAlign="center" activeDirection="center"
				 @change="navChange" activeLineBg="linear-gradient(to right, #699bf9, #3778fa)" activeLineWidth="80rpx"></graceNavBar>
			</view>
				
			<swiper class="scroll_contain" :style="{height:params.mainHeight+'px'}" :current="params.currentIndex" @change="swiperChange">
				<swiper-item class="scroll_auto" v-for="(item, index) in params.navListItem" :key="index">
					<scroll-view scroll-y="true">
						<view v-for="(item, index) in params.goodsList" class="goods_list" :key="index">
							<view class="title">
								<p>{{item.title}}{{params.mainHeight}}</p>
								<p>
									<text>{{item.title}}</text>
									<image src="../../static/logo.png" mode=""></image>
								</p>
							</view>
							<image :src="item.main_img" class="goods_img"></image>
						</view>
						<graceLoading :loadingType="params.loadingType"></graceLoading>
					</scroll-view>
				</swiper-item>
			</swiper>
			
		</view>
	</gracePage>
</template>
<script>
	import gracePage from "../../graceUI/components/gracePage.vue";
	import graceNavBar from "../../graceUI/components/graceNavBar.vue";
	import graceLoading from '../../graceUI/components/graceLoading.vue';
	export default {
		data() {
			return {
				params: {
					currentIndex: 0,
					navlist: [],
					navListItem: ['关注', '推荐', '体育', '热点', '国内', '国外', '其他'],
					goodsList: [],
					mainHeight: 600,
					loadingTypes : [],
					pageInfo: {
						pageSize: '',
						pageNum: "",
						total: "",
						isOver: false,
					},
				},

			}
		},
		onReady: function() {
			setTimeout(() => {
				uni.createSelectorQuery().select('#gBody').fields({
					size: true
				}, (res) => {
					this.params.mainHeight = res.height;
				}).exec();
			}, 1000);
		},
		methods: {
			navChange: function(e) {
				this.params.currentIndex = e;
			},
			swiperChange: function(e) {
				var index = e.detail.current;
				this.params.currentIndex = index;
			},
			loadNav: function() {
				let _self = this;
				let url = '';
				// console.log(_self.$Json("","","",function(res){
				// 	console.log(res)
				// },"",'navlist')
				_self.$Json('get', url, '', function(res) {
					_self.params.navlist = res.data;
					_self.params.navListItem = [];
					for (let i of res.data) {
						_self.params.navListItem.push(i.name)
					}
				}, function(res) {
					console.log(res)
				}, 'navlist')
			},
			loadMessage: function() {
				let _self = this;
				let url = '';
				let body = {
					pageSize: _self.params.pageInfo.pageSize,
					pageNum: _self.params.pageInfo.pageNum,

				}
				_self.$Json('get', url, '', function(res) {
					let result = res.data;
					_self.params.goodsList.push(...result)

					console.log(res)
				}, function(res) {
					console.log(res)
				}, 'goodsList')
				uni.stopPullDownRefresh()
			}
		},
		components: {
			gracePage,
			graceNavBar
		},
		onPullDownRefresh: function() {
			let _self = this;
			let pageInfo = _self.params.pageInfo;
			pageInfo.pageNum = 0;
			pageInfo.total = 0;
			_self.params.goodsList = [];
			pageInfo.isOver = false;
			_self.loadMessage();
		},
		onReachBottom: function() {
			console.log('xxxxx')
			
		},
		onLoad() {
			let _self = this;
			_self.loadNav();
			_self.loadMessage();
		}
	}
</script>
<style lang="less" scoped>
	.grace-page-header-nav {
		display: none;
	}

	.indexPage {
		.NavBar {
			padding: 25upx 0;
			position: fixed;
			top: 0px;
			z-index: 1000;
			width: 100%;
		}

		.scroll_contain {
			padding: 105upx 0 100upx;
			box-sizing: border-box;

			.scroll_auto {
				overflow-y: auto;

				.goods_list {
					padding: 0 20upx;
					margin-bottom: 20upx;
					background-color: rgba(255, 255, 255, 1);

					.title {
						padding: 0 10upx;
						font-size: 24upx;
						color: rgba(64, 64, 64, 1);
						line-height: 73upx;
						font-weight: 700;
						display: flex;
						justify-content: space-between;

						&>p:nth-child(2) {
							color: rgba(96, 96, 96, 1);
							font-weight: 500;
							font-size: 20upx;

							image {
								width: 42upx;
								height: 42upx;
								vertical-align: middle;
								margin: 0 0 0 10upx;
								border-radius: 50%;
							}
						}


					}

					.goods_img {
						width: 100%;
						height: 288upx;
					}
				}
			}
		}

	}
</style>
